package DataBase;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import DataObjects.Submit;

public class SubmitFire {
	
	
	Submit submit;
	
	
	public SubmitFire(Submit submit)
	{
		this.submit=submit;
	}
	
	
	public int submit()
	{
		int status=0;
		
		SQLConnection sc=new SQLConnection();
		try {
			
					
			PreparedStatement ps = sc.getConnection().prepareStatement("UPDATE Fire SET isSubmitted='1' WHERE orderId=?  AND rname=? AND (extraName=? OR extraName is null) AND (souceName=? OR souceName is null) AND (actionLevel=? OR actionLevel is null) AND (comments=? OR comments is null)  ORDER BY orderId DESC LIMIT 1;");	
			sc.getConnection().setAutoCommit(false);
			ps.setInt(1,Integer.parseInt(submit.getOrderId()));
			ps.setString(2, submit.getRecipe());
			
			if(submit.getExtra()!=null) {ps.setString(3, submit.getExtra());}
			else {ps.setString(3, " ");}
				
			if(submit.getSouce()!=null) ps.setString(4, submit.getSouce());
			else ps.setString(4, " ");
			
			
			if(submit.getActionLevel()!=null) ps.setString(5, submit.getActionLevel());
			else ps.setString(5, " ");
			
			if(submit.getComments()!=null) ps.setString(6, submit.getComments());
			else ps.setString(6, " ");
			
			ps.executeUpdate();
			
			sc.getConnection().commit();
			sc.getConnection().close();
			ps.close();
			status=1;
		}
		
		catch (SQLException e) {
			// TODO Auto-generated catch block
			status=0;
			e.printStackTrace();
		}
		
		
		
		
		return status;
	}

}
